﻿using System.Threading;

namespace BGYMqttServer.Models
{
    /// <summary>
    /// 表示mqtt消息
    /// </summary>
    public class MqttMessage
    {
        private static int idValue = 0;

        /// <summary>
        /// 创建id
        /// </summary>
        /// <returns></returns>
        public static int CreateId() => Interlocked.Increment(ref idValue);
         

        /// <summary>
        /// 电梯查询的指令值 
        /// </summary>
        public MqttApi Api { get; set; }

        /// <summary>
        /// 发送或回复时的unix时间戳(s)
        /// </summary>
        public long Time { get; set; }

        /// <summary>
        /// 表示消息的唯一标识符，门口机回复时，消息id为请求时的id
        /// </summary>
        public int Id { get; set; }
    }

    /// <summary>
    /// 表示mqtt消息
    /// </summary>
    /// <typeparam name="TBody"></typeparam>
    public class MqttMessage<TBody> : MqttMessage
    {
        /// <summary>
        /// 内容体
        /// </summary>
        public TBody Body { get; set; }
    }
}
